package com.hylanda.pb.service;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.hylanda.pb.dao.ReportModelDao;
import com.hylanda.pb.entity.ReportModel;
import com.hylanda.pb.model.ReportModelQo;


@Service
public class ReportModelService {
    @Autowired
    private ReportModelDao reportModelDao;

    public ReportModel findById(String id) {
    	ReportModel reportModel = reportModelDao.findEntity(ReportModel.class, id,"processorId");
        return reportModel;
    }

    public ReportModel create(ReportModel reportModel) {
        ReportModel newReportModel = reportModelDao.save(reportModel);
        return newReportModel;
    }

    public int update(ReportModel reportModel) {
        return reportModelDao.update(reportModel,"processorId");
    }

    public void delete(Long id) {
    	reportModelDao.delete(ReportModel.class, id,"processorId");
    }

    public Page<ReportModel> findPage(ReportModelQo reportModelQo){
       Pageable pageable = new PageRequest(reportModelQo.getPage(), reportModelQo.getSize(), new Sort(Sort.Direction.ASC, "processorId"));
       Map<String, Object> fieldsFilter=new HashMap<String, Object>();
       if(StringUtils.isNotEmpty(reportModelQo.getDatabase_name())){
    	   fieldsFilter.put("database_name", reportModelQo.getDatabase_name());
       }
       return reportModelDao.findPage(pageable, ReportModel.class, fieldsFilter);
    }
   

}
